#retrying 模块
#用于刷新页面直到成功为止 通过装饰器的方式使用
#timeout 参数
#一段时间未响应则抛出异常
from retrying import retry
from fake_useragent import UserAgent
import requests
import time
@retry(stop_max_attempt_number=3)
def gets():
    url = "https://www.baidu.com/"
    headers = {"User-Agent": UserAgent().random}
    res = requests.get(url, headers=headers,timeout=5)
    print(len(res.content.decode()))
try:
    gets()
except Exception as e:
    print(e)